<?php

class spotify {

	private $endpoint = 'http://ws.spotify.com/search/1/album.json';
	
	// queries the spotify metadata API and returns results
	// expects prepped search string
	private function get_json($query) {
		$json_url = "{$this->endpoint}?q=$query";
		return json_decode(file_get_contents($json_url));
	}
	
	private function search($search_string) {
		$search_string = prep_search_string($search_string);
		return $this->get_json($search_string);
	}
	
	public function get_album_link($album_name) {
		$results = $this->search($album_name);
		$first_result = $results->albums[0];
		$first_result_link = $first_result->href;
		
		if ($first_result_link)
			return $first_result_link;
		else
			return false;
	}
}